from pydantic import BaseModel
from typing import Optional, List, Any
from datetime import datetime

# 评论基础模型
class CommentBase(BaseModel):
    content: str
    entity_type: str  # issue, case, etc.
    entity_id: int
    parent_id: Optional[int] = None

# 评论创建模型
class CommentCreate(BaseModel):
    content: str
    parent_id: Optional[int] = None

# 评论更新模型
class CommentUpdate(BaseModel):
    content: Optional[str] = None

# 评论数据库模型
class CommentInDB(CommentBase):
    id: int
    author_id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        orm_mode = True

# 评论响应模型，包含作者信息
class CommentResponse(BaseModel):
    id: int
    content: str
    entity_type: str
    entity_id: int
    parent_id: Optional[int] = None
    author_id: int
    author_username: str
    created_at: datetime
    updated_at: datetime
    replies: Optional[List[Any]] = []

    class Config:
        orm_mode = True